package com.maybach.core.msg.impl;

import com.maybach.core.msg.IMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by houenxun on 16/2/22.
 */
public abstract class AbstractMsgService implements IMsgService {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public String sendMsg(String target, String msg) {
        // 1. 创建短信纪录
        // 2. 验证短信有效性,如果有效继续

        if (!valid(target)) {
            logger.error("目标不合法,target={}", target);
            return "目标不合法";
        }
        // 3. 发送短信
        return sendMsg0(target, msg);
    }

    /**
     * 验证目标的有效性
     *
     * @param target
     * @return
     */
    protected abstract boolean valid(String target);

    protected abstract String sendMsg0(String target, String msg);
}
